﻿namespace QLPhongKham.UC
{
    using ConfigDatabase.Class;
    using DevExpress.Data;
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Base;
    using DevExpress.XtraGrid.Views.Grid;
    using DevExpress.XtraTab;
    using QLPhongKham.Access;
    using QLPhongKham.BaseClass.VienPhi;
    using QLPhongKham.Report;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class ucvp_dmquyenso : XtraUserControl
    {
        private ConnectDatabase _condata;
        private int _iiddangnhap;
        private General _xuli;
        private SimpleButton btnboqua;
        private SimpleButton btnin;
        private SimpleButton btnketthuc;
        private SimpleButton btnluu;
        private SimpleButton btnmoi;
        private SimpleButton btnsua;
        private SimpleButton btnxoa;
        private CheckEdit chksudung;
        private IContainer components;
        private GridControl gridds;
        private GridColumn gridds_denso;
        private GridColumn gridds_id;
        private GridColumn gridds_ma;
        private GridColumn gridds_sodangghi;
        private GridColumn gridds_sudung;
        private GridColumn gridds_ten;
        private GridColumn gridds_tuso;
        private GridView gridView1;
        private Label label1;
        private Label label2;
        private Label label3;
        private Label label4;
        private Label label5;
        private Label label6;
        private RepositoryItemCheckEdit repositoryItemCheckEdit1;
        private RepositoryItemTextEdit repositoryItemTextEdit1;
        private TextEdit txtdenso;
        private TextEdit txtma;
        private TextEdit txtsodangdung;
        private TextEdit txtten;
        private TextEdit txttuso;

        public ucvp_dmquyenso()
        {
            this._iiddangnhap = 0;
            this.components = null;
            this.InitializeComponent();
            this._condata = new ConnectDatabase();
        }

        public ucvp_dmquyenso(ConnectDatabase condata, int iddangnhap)
        {
            this._iiddangnhap = 0;
            this.components = null;
            this.InitializeComponent();
            this._condata = condata;
            this._iiddangnhap = iddangnhap;
        }

        private void btnboqua_Click(object sender, EventArgs e)
        {
            this.f_Control_enable(false);
        }

        private void btnin_Click(object sender, EventArgs e)
        {
            DataTable dataSource = (DataTable) this.gridds.DataSource;
            dataSource.AcceptChanges();
            DataSet data = new DataSet();
            data.Tables.Add(dataSource.Copy());
            data.WriteXml("dataxml//v_dmquyenso.xml", XmlWriteMode.WriteSchema);
            new XtraReport1().f_load(data, "v_dmquyenso.repx");
        }

        private void btnketthuc_Click(object sender, EventArgs e)
        {
            try
            {
                XtraTabPage parent = (XtraTabPage) base.Parent;
                XtraTabControl control = (XtraTabControl) parent.Parent;
                control.TabPages.Remove(parent);
            }
            catch
            {
            }
        }

        private void btnluu_Click(object sender, EventArgs e)
        {
            if (this.f_kiemtra_luu())
            {
                dtovpDMQuyenSo so = new dtovpDMQuyenSo(this._condata) {
                    pKIHIEU = this.txtma.Text,
                    pTEN = this.txtten.Text,
                    pID = int.Parse(this.txtma.Tag.ToString()),
                    pIDDANGNHAP = this._iiddangnhap,
                    pSUDUNG = this.chksudung.Checked,
                    pTUSO = Convert.ToInt32(this.txttuso.EditValue),
                    pDENSO = Convert.ToInt32(this.txtdenso.EditValue),
                    pSODANGGHI = Convert.ToInt32(this.txtsodangdung.EditValue),
                    pTENMAYTINH = Environment.MachineName
                };
                if (this.txtma.Tag.ToString() == "0")
                {
                    so.pID = so.GetIDInsert();
                    if (!so.Insert())
                    {
                        MessageBox.Show("Kh\x00f4ng lưu được th\x00f4ng tin quyển sổ", "Th\x00f4ng b\x00e1o");
                        return;
                    }
                }
                else if (!so.Update())
                {
                    MessageBox.Show("Kh\x00f4ng lưu được th\x00f4ng tin quyển sổ", "Th\x00f4ng b\x00e1o");
                    return;
                }
                this.f_Loaddata_dmvp();
                this.f_Control_enable(false);
            }
        }

        private void btnmoi_Click(object sender, EventArgs e)
        {
            this.f_Loadcontrol_dmvp(0, "", "", 0, 0, true, 0);
            this.f_Control_enable(true);
            base.ActiveControl = this.txtma;
        }

        private void btnsua_Click(object sender, EventArgs e)
        {
            this.f_Control_enable(true);
            this.txtten.Focus();
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            if ((this.txtma.Tag.ToString() != "0") && (MessageBox.Show("Bạn c\x00f3 chắc chắn muốn hủy th\x00f4ng tin:\n" + this.txtma.Text + " - " + this.txtten.Text + " ?", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.No))
            {
                try
                {
                    dtovpDMVienPhi phi = new dtovpDMVienPhi(this._condata) {
                        pID = int.Parse(this.txtma.Tag.ToString())
                    };
                    if (!phi.Delete())
                    {
                        MessageBox.Show("Hủy kh\x00f4ng th\x00e0nh c\x00f4ng.Vui l\x00f2ng kiểm tra lại.", "Th\x00f4ng b\x00e1o");
                    }
                    else
                    {
                        MessageBox.Show("Đ\x00e3 hủy th\x00e0nh c\x00f4ng.", "Th\x00f4ng b\x00e1o");
                        this.f_Loaddata_dmvp();
                    }
                }
                catch
                {
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void f_Control_enable(bool chophep)
        {
            this.btnluu.Enabled = this.btnboqua.Enabled = chophep;
            this.btnmoi.Enabled = this.btnxoa.Enabled = this.btnsua.Enabled = this.btnketthuc.Enabled = !chophep;
            this.gridds.Enabled = !chophep;
            this.txtma.Properties.ReadOnly = this.txtten.Properties.ReadOnly = this.txttuso.Properties.ReadOnly = this.txtdenso.Properties.ReadOnly = this.txtsodangdung.Properties.ReadOnly = !chophep;
            this.chksudung.Enabled = chophep;
        }

        private bool f_kiemtra_luu()
        {
            if (Convert.ToInt32(this.txttuso.EditValue) > Convert.ToInt32(this.txtdenso.EditValue))
            {
                MessageBox.Show("Số bắt đầu ghi kh\x00f4ng được lớn hơn số kết th\x00fac.", "Th\x00f4ng b\x00e1o");
                this.txttuso.Focus();
                return false;
            }
            if (Convert.ToInt32(this.txttuso.EditValue) > Convert.ToInt32(this.txtsodangdung.EditValue))
            {
                MessageBox.Show("Số đang ghi kh\x00f4ng được nhỏ hơn số bắt đầu ghi.", "Th\x00f4ng b\x00e1o");
                this.txtsodangdung.Focus();
                return false;
            }
            if (Convert.ToInt32(this.txtdenso.EditValue) < Convert.ToInt32(this.txtsodangdung.EditValue))
            {
                MessageBox.Show("Số đang ghi kh\x00f4ng được lớn hơn số kết th\x00fac ghi.", "Th\x00f4ng b\x00e1o");
                this.txtsodangdung.Focus();
                return false;
            }
            return true;
        }

        private void f_Loadcontrol_dmvp(int id, string ma, string ten, int tuso, int denso, bool dangdung, int sodangghi)
        {
            this.txtma.Text = ma;
            this.txtma.Tag = id.ToString();
            this.txtten.Text = ten;
            this.txttuso.Text = tuso.ToString();
            this.txtdenso.Text = denso.ToString();
            this.txtsodangdung.Text = sodangghi.ToString();
            this.chksudung.Checked = dangdung;
        }

        private void f_Loaddata_dmvp()
        {
            try
            {
                this.gridds.DataSource = new dtovpDMQuyenSo(this._xuli.pConFigData).LoadAll();
            }
            catch
            {
            }
        }

        private void f_loadinfo_dmsanpham(int indexrow)
        {
            try
            {
                this.f_Loadcontrol_dmvp(int.Parse(this.gridView1.GetRowCellValue(indexrow, this.gridds_id).ToString()), this.gridView1.GetRowCellValue(indexrow, this.gridds_ma).ToString(), this.gridView1.GetRowCellValue(indexrow, this.gridds_ten).ToString(), Convert.ToInt32(this.gridView1.GetRowCellValue(indexrow, this.gridds_tuso).ToString()), Convert.ToInt32(this.gridView1.GetRowCellValue(indexrow, this.gridds_denso).ToString()), this.gridView1.GetRowCellValue(indexrow, this.gridds_sudung).ToString() == "1", Convert.ToInt32(this.gridView1.GetRowCellValue(indexrow, this.gridds_sodangghi).ToString()));
            }
            catch
            {
            }
        }

        private void gridView1_CustomSummaryCalculate(object sender, CustomSummaryEventArgs e)
        {
        }

        private void gridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            int indexrow = 0;
            try
            {
                if (this.gridView1.IsFocusedView)
                {
                    indexrow = this.gridView1.GetSelectedRows()[0];
                    this.f_loadinfo_dmsanpham(indexrow);
                }
            }
            catch
            {
            }
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(ucvp_dmquyenso));
            this.label1 = new Label();
            this.label2 = new Label();
            this.txtma = new TextEdit();
            this.label3 = new Label();
            this.txtten = new TextEdit();
            this.label4 = new Label();
            this.txttuso = new TextEdit();
            this.btnmoi = new SimpleButton();
            this.btnluu = new SimpleButton();
            this.btnsua = new SimpleButton();
            this.btnxoa = new SimpleButton();
            this.btnketthuc = new SimpleButton();
            this.gridView1 = new GridView();
            this.gridds_ma = new GridColumn();
            this.repositoryItemTextEdit1 = new RepositoryItemTextEdit();
            this.gridds_ten = new GridColumn();
            this.gridds_id = new GridColumn();
            this.gridds_tuso = new GridColumn();
            this.gridds_denso = new GridColumn();
            this.gridds_sudung = new GridColumn();
            this.repositoryItemCheckEdit1 = new RepositoryItemCheckEdit();
            this.gridds = new GridControl();
            this.btnboqua = new SimpleButton();
            this.btnin = new SimpleButton();
            this.label5 = new Label();
            this.txtdenso = new TextEdit();
            this.chksudung = new CheckEdit();
            this.label6 = new Label();
            this.txtsodangdung = new TextEdit();
            this.gridds_sodangghi = new GridColumn();
            this.txtma.Properties.BeginInit();
            this.txtten.Properties.BeginInit();
            this.txttuso.Properties.BeginInit();
            this.gridView1.BeginInit();
            this.repositoryItemTextEdit1.BeginInit();
            this.repositoryItemCheckEdit1.BeginInit();
            this.gridds.BeginInit();
            this.txtdenso.Properties.BeginInit();
            this.chksudung.Properties.BeginInit();
            this.txtsodangdung.Properties.BeginInit();
            base.SuspendLayout();
            this.label1.BackColor = Color.ForestGreen;
            this.label1.Dock = DockStyle.Top;
            this.label1.Font = new Font("Tahoma", 16f);
            this.label1.ForeColor = Color.Yellow;
            this.label1.Location = new Point(0, 0);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x2d9, 0x30);
            this.label1.TabIndex = 1;
            this.label1.Text = "DANH MỤC QUYỂN SỔ";
            this.label1.TextAlign = ContentAlignment.MiddleCenter;
            this.label2.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.label2.Font = new Font("Tahoma", 10f);
            this.label2.Location = new Point(5, 0x14c);
            this.label2.Name = "label2";
            this.label2.Size = new Size(70, 0x13);
            this.label2.TabIndex = 2;
            this.label2.Text = "K\x00ed hiệu:";
            this.label2.TextAlign = ContentAlignment.TopRight;
            this.txtma.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.txtma.Location = new Point(0x4a, 0x14b);
            this.txtma.Name = "txtma";
            this.txtma.Properties.CharacterCasing = CharacterCasing.Upper;
            this.txtma.Size = new Size(100, 20);
            this.txtma.TabIndex = 0;
            this.txtma.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.label3.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.label3.Font = new Font("Tahoma", 10f);
            this.label3.Location = new Point(170, 0x14c);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x4c, 0x13);
            this.label3.TabIndex = 2;
            this.label3.Text = "Quyển sổ:";
            this.label3.TextAlign = ContentAlignment.TopRight;
            this.txtten.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
            this.txtten.Location = new Point(0xf3, 0x14b);
            this.txtten.Name = "txtten";
            this.txtten.Size = new Size(480, 20);
            this.txtten.TabIndex = 1;
            this.txtten.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.txtten.Validated += new EventHandler(this.txtten_Validated);
            this.label4.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.label4.Font = new Font("Tahoma", 10f);
            this.label4.Location = new Point(0x15, 0x166);
            this.label4.Name = "label4";
            this.label4.Size = new Size(0x36, 0x13);
            this.label4.TabIndex = 2;
            this.label4.Text = "Từ số:";
            this.label4.TextAlign = ContentAlignment.TopRight;
            this.txttuso.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.txttuso.Location = new Point(0x4a, 0x165);
            this.txttuso.Name = "txttuso";
            this.txttuso.Size = new Size(100, 20);
            this.txttuso.TabIndex = 2;
            this.txttuso.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.txttuso.Validated += new EventHandler(this.txttuso_Validated);
            this.btnmoi.Anchor = AnchorStyles.Bottom;
            this.btnmoi.Appearance.Options.UseTextOptions = true;
            this.btnmoi.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnmoi.Image = Properties.Resources.imgnew;// (Image)manager.GetObject("btnmoi.Image");
            this.btnmoi.Location = new Point(5, 0x185);
            this.btnmoi.Name = "btnmoi";
            this.btnmoi.Size = new Size(0x4b, 0x17);
            this.btnmoi.TabIndex = 6;
            this.btnmoi.Text = " &Mới [F2]";
            this.btnmoi.Click += new EventHandler(this.btnmoi_Click);
            this.btnluu.Anchor = AnchorStyles.Bottom;
            this.btnluu.Appearance.Options.UseTextOptions = true;
            this.btnluu.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnluu.Image = Properties.Resources.imgsave;// (Image)manager.GetObject("btnluu.Image");
            this.btnluu.Location = new Point(0x53, 0x185);
            this.btnluu.Name = "btnluu";
            this.btnluu.Size = new Size(0x4b, 0x17);
            this.btnluu.TabIndex = 5;
            this.btnluu.Text = " &Lưu [F5]";
            this.btnluu.Click += new EventHandler(this.btnluu_Click);
            this.btnsua.Anchor = AnchorStyles.Bottom;
            this.btnsua.Appearance.Options.UseTextOptions = true;
            this.btnsua.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnsua.Image = Properties.Resources.imgedit;// (Image)manager.GetObject("btnsua.Image");
            this.btnsua.Location = new Point(0xa1, 0x185);
            this.btnsua.Name = "btnsua";
            this.btnsua.Size = new Size(0x4b, 0x17);
            this.btnsua.TabIndex = 8;
            this.btnsua.Text = " &Sửa [F3]";
            this.btnsua.Click += new EventHandler(this.btnsua_Click);
            this.btnxoa.Anchor = AnchorStyles.Bottom;
            this.btnxoa.Image = Properties.Resources.imgdelete;// (Image)manager.GetObject("btnxoa.Image");
            this.btnxoa.Location = new Point(0x148, 0x185);
            this.btnxoa.Name = "btnxoa";
            this.btnxoa.Size = new Size(0x4b, 0x17);
            this.btnxoa.TabIndex = 10;
            this.btnxoa.Text = " &Hủy [F7]";
            this.btnxoa.Visible = false;
            this.btnxoa.Click += new EventHandler(this.btnxoa_Click);
            this.btnketthuc.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnketthuc.Appearance.Options.UseTextOptions = true;
            this.btnketthuc.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            this.btnketthuc.Image = Properties.Resources.imgclose;// (Image)manager.GetObject("btnketthuc.Image");
            this.btnketthuc.Location = new Point(0x26e, 0x185);
            this.btnketthuc.Name = "btnketthuc";
            this.btnketthuc.Size = new Size(0x65, 0x17);
            this.btnketthuc.TabIndex = 13;
            this.btnketthuc.Text = " &Kết th\x00fac [F12]";
            this.btnketthuc.Click += new EventHandler(this.btnketthuc_Click);
            this.gridView1.Appearance.ColumnFilterButton.BackColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.ColumnFilterButton.BorderColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.ColumnFilterButton.ForeColor = Color.Black;
            this.gridView1.Appearance.ColumnFilterButton.Options.UseBackColor = true;
            this.gridView1.Appearance.ColumnFilterButton.Options.UseBorderColor = true;
            this.gridView1.Appearance.ColumnFilterButton.Options.UseForeColor = true;
            this.gridView1.Appearance.ColumnFilterButtonActive.BackColor = Color.FromArgb(0xd3, 0xe2, 0xd8);
            this.gridView1.Appearance.ColumnFilterButtonActive.BorderColor = Color.FromArgb(0xd3, 0xe2, 0xd8);
            this.gridView1.Appearance.ColumnFilterButtonActive.ForeColor = Color.Black;
            this.gridView1.Appearance.ColumnFilterButtonActive.Options.UseBackColor = true;
            this.gridView1.Appearance.ColumnFilterButtonActive.Options.UseBorderColor = true;
            this.gridView1.Appearance.ColumnFilterButtonActive.Options.UseForeColor = true;
            this.gridView1.Appearance.Empty.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.Empty.BackColor2 = Color.White;
            this.gridView1.Appearance.Empty.Options.UseBackColor = true;
            this.gridView1.Appearance.EvenRow.BackColor = Color.FromArgb(0xdd, 0xe3, 0xf5);
            this.gridView1.Appearance.EvenRow.BorderColor = Color.FromArgb(0xdd, 0xe3, 0xf5);
            this.gridView1.Appearance.EvenRow.ForeColor = Color.Black;
            this.gridView1.Appearance.EvenRow.Options.UseBackColor = true;
            this.gridView1.Appearance.EvenRow.Options.UseBorderColor = true;
            this.gridView1.Appearance.EvenRow.Options.UseForeColor = true;
            this.gridView1.Appearance.FilterCloseButton.BackColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.FilterCloseButton.BorderColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.FilterCloseButton.ForeColor = Color.Black;
            this.gridView1.Appearance.FilterCloseButton.Options.UseBackColor = true;
            this.gridView1.Appearance.FilterCloseButton.Options.UseBorderColor = true;
            this.gridView1.Appearance.FilterCloseButton.Options.UseForeColor = true;
            this.gridView1.Appearance.FilterPanel.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.FilterPanel.BackColor2 = Color.White;
            this.gridView1.Appearance.FilterPanel.ForeColor = Color.Black;
            this.gridView1.Appearance.FilterPanel.Options.UseBackColor = true;
            this.gridView1.Appearance.FilterPanel.Options.UseForeColor = true;
            this.gridView1.Appearance.FixedLine.BackColor = Color.FromArgb(0x75, 0x88, 0x7a);
            this.gridView1.Appearance.FixedLine.Options.UseBackColor = true;
            this.gridView1.Appearance.FocusedCell.BackColor = Color.White;
            this.gridView1.Appearance.FocusedCell.ForeColor = Color.Black;
            this.gridView1.Appearance.FocusedCell.Options.UseBackColor = true;
            this.gridView1.Appearance.FocusedCell.Options.UseForeColor = true;
            this.gridView1.Appearance.FocusedRow.BackColor = Color.FromArgb(0x81, 0xab, 0xb1);
            this.gridView1.Appearance.FocusedRow.ForeColor = Color.White;
            this.gridView1.Appearance.FocusedRow.Options.UseBackColor = true;
            this.gridView1.Appearance.FocusedRow.Options.UseForeColor = true;
            this.gridView1.Appearance.FooterPanel.BackColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.FooterPanel.BorderColor = Color.FromArgb(0xca, 0xdd, 0xd0);
            this.gridView1.Appearance.FooterPanel.ForeColor = Color.Black;
            this.gridView1.Appearance.FooterPanel.Options.UseBackColor = true;
            this.gridView1.Appearance.FooterPanel.Options.UseBorderColor = true;
            this.gridView1.Appearance.FooterPanel.Options.UseForeColor = true;
            this.gridView1.Appearance.GroupButton.BackColor = Color.FromArgb(0xb2, 0xd1, 0xbc);
            this.gridView1.Appearance.GroupButton.BorderColor = Color.FromArgb(0xb2, 0xd1, 0xbc);
            this.gridView1.Appearance.GroupButton.Options.UseBackColor = true;
            this.gridView1.Appearance.GroupButton.Options.UseBorderColor = true;
            this.gridView1.Appearance.GroupFooter.BackColor = Color.FromArgb(0xd7, 0xea, 0xdd);
            this.gridView1.Appearance.GroupFooter.BorderColor = Color.FromArgb(0xd7, 0xea, 0xdd);
            this.gridView1.Appearance.GroupFooter.ForeColor = Color.Black;
            this.gridView1.Appearance.GroupFooter.Options.UseBackColor = true;
            this.gridView1.Appearance.GroupFooter.Options.UseBorderColor = true;
            this.gridView1.Appearance.GroupFooter.Options.UseForeColor = true;
            this.gridView1.Appearance.GroupPanel.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.GroupPanel.BackColor2 = Color.White;
            this.gridView1.Appearance.GroupPanel.ForeColor = Color.Black;
            this.gridView1.Appearance.GroupPanel.Options.UseBackColor = true;
            this.gridView1.Appearance.GroupPanel.Options.UseForeColor = true;
            this.gridView1.Appearance.GroupRow.BackColor = Color.FromArgb(0xd7, 0xea, 0xdd);
            this.gridView1.Appearance.GroupRow.BorderColor = Color.FromArgb(0xd7, 0xea, 0xdd);
            this.gridView1.Appearance.GroupRow.ForeColor = Color.Black;
            this.gridView1.Appearance.GroupRow.Options.UseBackColor = true;
            this.gridView1.Appearance.GroupRow.Options.UseBorderColor = true;
            this.gridView1.Appearance.GroupRow.Options.UseForeColor = true;
            this.gridView1.Appearance.HeaderPanel.BackColor = Color.FromArgb(0xd3, 0xe2, 0xd8);
            this.gridView1.Appearance.HeaderPanel.BorderColor = Color.FromArgb(0xd3, 0xe2, 0xd8);
            this.gridView1.Appearance.HeaderPanel.ForeColor = Color.Black;
            this.gridView1.Appearance.HeaderPanel.Options.UseBackColor = true;
            this.gridView1.Appearance.HeaderPanel.Options.UseBorderColor = true;
            this.gridView1.Appearance.HeaderPanel.Options.UseForeColor = true;
            this.gridView1.Appearance.HideSelectionRow.BackColor = Color.FromArgb(0xba, 0xd3, 0xd7);
            this.gridView1.Appearance.HideSelectionRow.ForeColor = Color.FromArgb(0x68, 130, 0x86);
            this.gridView1.Appearance.HideSelectionRow.Options.UseBackColor = true;
            this.gridView1.Appearance.HideSelectionRow.Options.UseForeColor = true;
            this.gridView1.Appearance.HorzLine.BackColor = Color.FromArgb(0xac, 0xc5, 180);
            this.gridView1.Appearance.HorzLine.BorderColor = Color.FromArgb(0x75, 0x88, 0x7a);
            this.gridView1.Appearance.HorzLine.Options.UseBackColor = true;
            this.gridView1.Appearance.HorzLine.Options.UseBorderColor = true;
            this.gridView1.Appearance.OddRow.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.OddRow.BorderColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.OddRow.ForeColor = Color.Black;
            this.gridView1.Appearance.OddRow.Options.UseBackColor = true;
            this.gridView1.Appearance.OddRow.Options.UseBorderColor = true;
            this.gridView1.Appearance.OddRow.Options.UseForeColor = true;
            this.gridView1.Appearance.Preview.BackColor = Color.FromArgb(250, 250, 240);
            this.gridView1.Appearance.Preview.Font = new Font("Verdana", 7.5f);
            this.gridView1.Appearance.Preview.ForeColor = Color.FromArgb(0x68, 130, 0x86);
            this.gridView1.Appearance.Preview.Options.UseBackColor = true;
            this.gridView1.Appearance.Preview.Options.UseFont = true;
            this.gridView1.Appearance.Preview.Options.UseForeColor = true;
            this.gridView1.Appearance.Row.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.Row.ForeColor = Color.Black;
            this.gridView1.Appearance.Row.Options.UseBackColor = true;
            this.gridView1.Appearance.Row.Options.UseForeColor = true;
            this.gridView1.Appearance.RowSeparator.BackColor = Color.FromArgb(0xf2, 0xf4, 0xec);
            this.gridView1.Appearance.RowSeparator.BackColor2 = Color.White;
            this.gridView1.Appearance.RowSeparator.Options.UseBackColor = true;
            this.gridView1.Appearance.SelectedRow.BackColor = Color.FromArgb(0x9f, 0xc9, 0xcf);
            this.gridView1.Appearance.SelectedRow.ForeColor = Color.Black;
            this.gridView1.Appearance.SelectedRow.Options.UseBackColor = true;
            this.gridView1.Appearance.SelectedRow.Options.UseForeColor = true;
            this.gridView1.Appearance.TopNewRow.BackColor = Color.White;
            this.gridView1.Appearance.TopNewRow.Options.UseBackColor = true;
            this.gridView1.Appearance.VertLine.BackColor = Color.FromArgb(0xac, 0xc5, 180);
            this.gridView1.Appearance.VertLine.BorderColor = Color.FromArgb(0x75, 0x88, 0x7a);
            this.gridView1.Appearance.VertLine.Options.UseBackColor = true;
            this.gridView1.Appearance.VertLine.Options.UseBorderColor = true;
            this.gridView1.Columns.AddRange(new GridColumn[] { this.gridds_ma, this.gridds_ten, this.gridds_id, this.gridds_tuso, this.gridds_denso, this.gridds_sudung, this.gridds_sodangghi });
            this.gridView1.GridControl = this.gridds;
            this.gridView1.Name = "gridView1";
            this.gridView1.OptionsView.AutoCalcPreviewLineCount = true;
            this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
            this.gridView1.OptionsView.EnableAppearanceOddRow = true;
            this.gridView1.OptionsView.ShowAutoFilterRow = true;
            this.gridView1.OptionsView.ShowFooter = true;
            this.gridView1.OptionsView.ShowGroupPanel = false;
            this.gridView1.CustomSummaryCalculate += new CustomSummaryEventHandler(this.gridView1_CustomSummaryCalculate);
            this.gridView1.FocusedRowChanged += new FocusedRowChangedEventHandler(this.gridView1_FocusedRowChanged);
            this.gridds_ma.Caption = "K\x00ed hiệu";
            this.gridds_ma.ColumnEdit = this.repositoryItemTextEdit1;
            this.gridds_ma.FieldName = "ma";
            this.gridds_ma.Name = "gridds_ma";
            this.gridds_ma.OptionsColumn.AllowEdit = false;
            this.gridds_ma.Summary.AddRange(new GridSummaryItem[] { new GridColumnSummaryItem(SummaryItemType.Count, "ma", "Số lượng={0:n0}") });
            this.gridds_ma.Visible = true;
            this.gridds_ma.VisibleIndex = 0;
            this.gridds_ma.Width = 0x51;
            this.repositoryItemTextEdit1.AutoHeight = false;
            this.repositoryItemTextEdit1.Name = "repositoryItemTextEdit1";
            this.repositoryItemTextEdit1.ReadOnly = true;
            this.gridds_ten.Caption = "T\x00ean quyển sổ";
            this.gridds_ten.ColumnEdit = this.repositoryItemTextEdit1;
            this.gridds_ten.FieldName = "ten";
            this.gridds_ten.Name = "gridds_ten";
            this.gridds_ten.OptionsColumn.AllowEdit = false;
            this.gridds_ten.OptionsColumn.FixedWidth = true;
            this.gridds_ten.Visible = true;
            this.gridds_ten.VisibleIndex = 1;
            this.gridds_ten.Width = 300;
            this.gridds_id.Caption = "id";
            this.gridds_id.FieldName = "id";
            this.gridds_id.Name = "gridds_id";
            this.gridds_tuso.Caption = "Từ số";
            this.gridds_tuso.ColumnEdit = this.repositoryItemTextEdit1;
            this.gridds_tuso.FieldName = "tuso";
            this.gridds_tuso.Name = "gridds_tuso";
            this.gridds_tuso.OptionsColumn.AllowEdit = false;
            this.gridds_tuso.Visible = true;
            this.gridds_tuso.VisibleIndex = 2;
            this.gridds_tuso.Width = 0x47;
            this.gridds_denso.Caption = "Đến số";
            this.gridds_denso.FieldName = "denso";
            this.gridds_denso.Name = "gridds_denso";
            this.gridds_denso.Visible = true;
            this.gridds_denso.VisibleIndex = 3;
            this.gridds_denso.Width = 0x40;
            this.gridds_sudung.Caption = "Sử dụng";
            this.gridds_sudung.ColumnEdit = this.repositoryItemCheckEdit1;
            this.gridds_sudung.FieldName = "sudung";
            this.gridds_sudung.Name = "gridds_sudung";
            this.gridds_sudung.OptionsColumn.AllowEdit = false;
            this.gridds_sudung.Visible = true;
            this.gridds_sudung.VisibleIndex = 5;
            this.gridds_sudung.Width = 0x6d;
            this.repositoryItemCheckEdit1.AutoHeight = false;
            this.repositoryItemCheckEdit1.Name = "repositoryItemCheckEdit1";
            int[] bits = new int[4];
            bits[0] = 1;
            this.repositoryItemCheckEdit1.ValueChecked = new decimal(bits);
            bits = new int[4];
            this.repositoryItemCheckEdit1.ValueUnchecked = new decimal(bits);
            this.gridds.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.gridds.Location = new Point(0, 0x33);
            this.gridds.MainView = this.gridView1;
            this.gridds.Name = "gridds";
            this.gridds.RepositoryItems.AddRange(new RepositoryItem[] { this.repositoryItemTextEdit1, this.repositoryItemCheckEdit1 });
            this.gridds.Size = new Size(0x2d9, 0x112);
            this.gridds.TabIndex = 7;
            this.gridds.ViewCollection.AddRange(new BaseView[] { this.gridView1 });
            this.gridds.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.btnboqua.Anchor = AnchorStyles.Bottom;
            this.btnboqua.Image = Properties.Resources.imgundo;// (Image)manager.GetObject("btnboqua.Image");
            this.btnboqua.Location = new Point(0xef, 0x185);
            this.btnboqua.Name = "btnboqua";
            this.btnboqua.Size = new Size(0x57, 0x17);
            this.btnboqua.TabIndex = 9;
            this.btnboqua.Text = " &Bỏ qua [F4]";
            this.btnboqua.Click += new EventHandler(this.btnboqua_Click);
            this.btnin.Anchor = AnchorStyles.Bottom;
            this.btnin.Image = Properties.Resources.imgprint;// (Image)manager.GetObject("btnin.Image");
            this.btnin.Location = new Point(0x196, 0x185);
            this.btnin.Name = "btnin";
            this.btnin.Size = new Size(0x30, 0x17);
            this.btnin.TabIndex = 11;
            this.btnin.Text = " &In";
            this.btnin.Visible = false;
            this.btnin.Click += new EventHandler(this.btnin_Click);
            this.label5.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.label5.Font = new Font("Tahoma", 10f);
            this.label5.Location = new Point(0xad, 0x166);
            this.label5.Name = "label5";
            this.label5.Size = new Size(0x47, 0x13);
            this.label5.TabIndex = 2;
            this.label5.Text = "Đến số:";
            this.label5.TextAlign = ContentAlignment.TopRight;
            this.txtdenso.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.txtdenso.Location = new Point(0xf3, 0x165);
            this.txtdenso.Name = "txtdenso";
            this.txtdenso.Size = new Size(100, 20);
            this.txtdenso.TabIndex = 3;
            this.txtdenso.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.txtdenso.Validated += new EventHandler(this.txttuso_Validated);
            this.chksudung.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.chksudung.Location = new Point(0x22f, 0x164);
            this.chksudung.Name = "chksudung";
            this.chksudung.Properties.Appearance.Font = new Font("Tahoma", 10f);
            this.chksudung.Properties.Appearance.Options.UseFont = true;
            this.chksudung.Properties.Caption = "Sử dụng";
            this.chksudung.Size = new Size(0x53, 0x15);
            this.chksudung.TabIndex = 12;
            this.label6.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.label6.Font = new Font("Tahoma", 10f);
            this.label6.Location = new Point(0x159, 0x165);
            this.label6.Name = "label6";
            this.label6.Size = new Size(0x6d, 0x13);
            this.label6.TabIndex = 2;
            this.label6.Text = "Số đang ghi:";
            this.label6.TextAlign = ContentAlignment.TopRight;
            this.txtsodangdung.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.txtsodangdung.Location = new Point(0x1c5, 0x165);
            this.txtsodangdung.Name = "txtsodangdung";
            this.txtsodangdung.Size = new Size(100, 20);
            this.txtsodangdung.TabIndex = 4;
            this.txtsodangdung.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.txtsodangdung.Validated += new EventHandler(this.txttuso_Validated);
            this.gridds_sodangghi.Caption = "Số đang ghi";
            this.gridds_sodangghi.FieldName = "sodangghi";
            this.gridds_sodangghi.Name = "gridds_sodangghi";
            this.gridds_sodangghi.OptionsColumn.AllowEdit = false;
            this.gridds_sodangghi.Visible = true;
            this.gridds_sodangghi.VisibleIndex = 4;
            this.gridds_sodangghi.Width = 0x56;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.txtdenso);
            base.Controls.Add(this.chksudung);
            base.Controls.Add(this.txtma);
            base.Controls.Add(this.gridds);
            base.Controls.Add(this.btnketthuc);
            base.Controls.Add(this.btnin);
            base.Controls.Add(this.btnxoa);
            base.Controls.Add(this.btnboqua);
            base.Controls.Add(this.btnsua);
            base.Controls.Add(this.btnluu);
            base.Controls.Add(this.btnmoi);
            base.Controls.Add(this.txtten);
            base.Controls.Add(this.label3);
            base.Controls.Add(this.txtsodangdung);
            base.Controls.Add(this.txttuso);
            base.Controls.Add(this.label4);
            base.Controls.Add(this.label2);
            base.Controls.Add(this.label6);
            base.Controls.Add(this.label1);
            base.Controls.Add(this.label5);
            base.Name = "ucvp_dmquyenso";
            base.Size = new Size(0x2d9, 0x19f);
            base.Load += new EventHandler(this.ucDMSanPham_Load);
            base.KeyDown += new KeyEventHandler(this.ucDMSanPham_KeyDown);
            this.txtma.Properties.EndInit();
            this.txtten.Properties.EndInit();
            this.txttuso.Properties.EndInit();
            this.gridView1.EndInit();
            this.repositoryItemTextEdit1.EndInit();
            this.repositoryItemCheckEdit1.EndInit();
            this.gridds.EndInit();
            this.txtdenso.Properties.EndInit();
            this.chksudung.Properties.EndInit();
            this.txtsodangdung.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void txtten_Validated(object sender, EventArgs e)
        {
            try
            {
                this.txtten.Text = this.txtten.Text.Substring(0, 1).ToUpper() + this.txtten.Text.Substring(1);
            }
            catch
            {
            }
        }

        private void txttuso_Validated(object sender, EventArgs e)
        {
            int num = 0;
            try
            {
                num = Convert.ToInt32(this.txtsodangdung.EditValue);
            }
            catch
            {
            }
            int num2 = 0;
            try
            {
                num2 = Convert.ToInt32(this.txttuso.EditValue);
            }
            catch
            {
            }
            int num3 = 0;
            try
            {
                num3 = Convert.ToInt32(this.txtdenso.EditValue);
            }
            catch
            {
            }
            try
            {
                if (num3 < num2)
                {
                    this.txtdenso.Text = num2.ToString();
                }
                if ((num > num3) || (num < num2))
                {
                    this.txtsodangdung.Text = num2.ToString();
                }
            }
            catch
            {
            }
        }

        private void ucDMSanPham_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{Tab}");
            }
            else if (e.KeyCode == Keys.F2)
            {
                if (this.btnmoi.Enabled)
                {
                    this.btnmoi_Click(null, null);
                }
            }
            else if (e.KeyCode == Keys.F3)
            {
                if (this.btnsua.Enabled)
                {
                    this.btnsua_Click(null, null);
                }
            }
            else if (e.KeyCode == Keys.F4)
            {
                if (this.btnboqua.Enabled)
                {
                    this.btnboqua_Click(null, null);
                }
            }
            else if (e.KeyCode == Keys.F5)
            {
                if (this.btnluu.Enabled)
                {
                    this.btnluu_Click(null, null);
                }
            }
            else if ((e.KeyCode == Keys.F12) && this.btnketthuc.Enabled)
            {
                this.btnketthuc_Click(null, null);
            }
        }

        private void ucDMSanPham_Load(object sender, EventArgs e)
        {
            this._xuli = new General(this._condata);
            this.f_Loaddata_dmvp();
            this.btnboqua_Click(null, null);
            this.f_loadinfo_dmsanpham(0);
        }
    }
}

